import type { ComponentDefinition } from '@/types/component'
import { ref } from 'vue'

class PluginManager {
  private plugins = ref<ComponentDefinition[]>([])

  // 注册插件组件
  registerComponent(component: ComponentDefinition) {
    this.plugins.value.push(component)
  }

  // 获取所有插件组件
  getAllComponents(): ComponentDefinition[] {
    return this.plugins.value
  }

  // 根据类型获取插件组件
  getComponentByType(type: string): ComponentDefinition | undefined {
    return this.plugins.value.find(comp => comp.type === type)
  }

  // 清空所有插件
  clear() {
    this.plugins.value = []
  }
}

export const pluginManager = new PluginManager() 